import Nprogress from 'nprogress';

export default {
  /**
   * 改变title标题
   * @param  {[type]} route [description]
   * @return {[type]}       [description]
   */
  replaceDocTitle(route) {
    let { title } = route.meta;

    title = route.query.title || title;

    if (title) {
      document.title = `${title} - ${process.env.VUE_APP_TITLE}`;
    }
  },

  /**
   * HTML上添加当前页的属性标记，便于某些css切换
   * @param {[type]} route [description]
   */
  addPageTag(route) {
    const docEl = document.documentElement;
    const { name = '' } = route;

    docEl.setAttribute('data-page', name);
  },

  closeLoading() {
    Nprogress.done();
  },
};
